package com.example.demo.java8;

import com.example.demo.BaseTest;
import org.junit.Test;

import java.util.stream.Stream;

/**
 * @description: 流
 * @author: luojm
 * @create: 2018-05-17 11:45
 **/
public class stream extends BaseTest {
//    1.collect
//    2.filter
//    3.distinc
//    4.limit
//    5.skip
//    6.map
//    7.flatMap
//    8.max min
//    9.reduce
    @Test
    public void reduceTest1(){
        int count = Stream.of(1,2,3)
                .reduce(0,(acc,element) -> acc + element);
        System.err.println(count);
    }
    @Test
    public void reduceTest2(){
        int count = Stream.of(1,2,3)
                .reduce(0,(acc,element) -> {
                    if(acc<3){
                        return acc + element;
                    }
                    return  acc;
                });
        System.err.println(count);
    }

//    10.Optional


}
